package com.dp.study.WebSocket.controller;


import com.dp.study.WebSocket.bean.InMessage;
import com.dp.study.WebSocket.service.SendMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.stereotype.Controller;

/**
 * Created by IntelliJ IDEA
 * User: DengPeng
 * Date: 2019/5/15 ,
 * Time: 18:12 ,
 * Email:dp9212@163.com .
 */
@Controller
public class WebSocketController {

    @Autowired
    private SendMessageService sendMessageService;

    /**
     * MessageMapping 同RequestMapping,WebSocket用，
     *                客户端发送数据的地址（需要加上WebSocketConfig类中消息代理配置的前缀(setApplicationDestinationPrefixes)），
     * @param message
     * @throws Exception
     */

    @MessageMapping("/hello")
    //@SendTo("/topic/game_rank") //需要返回值，自动转JSON,发送地址单一，无法通用
    public void greeting(InMessage message) throws Exception {
        Thread.sleep(1000); // simulated delay
        sendMessageService.sendTopicMessage("/topic/game_rank",message);
    }

}
